﻿#include "Prompt.h"
#include "Exception.h"
#include <conio.h>

/**
 * @brief 控制台输出提示并获取用户响应
 *
 * @param mess
 * @return string
 */
string prompt(string mess = "")
{
	string res;
	cout << mess << endl;
	cin >> res;
	return res;
}
/**
 * @brief 从控制台获取用户输入输入密码
 *
 * @param mess
 * @return string 密码
 */
string prompt_passoword(string mess = "")
{
	char password[100] = {0};
	cout << mess << endl;
	for (int i = 0; i < 100; i++)
	{
		password[i] = _getch();
		// 如果输入为换行，则结束输入
		if (password[i] == '\n' || password[i] == '\r')
		{
			password[i] = '\0';
			cout << endl;
			break;
		}
		else if (password[i] == '\3')
		{
			throw InterrputException();
		}
		else
		{
			cout << " *";
		}
	}
	return string(password);
}